//
//  CAISegmentCell.m
//  CAISegmentedPageController
//
//  Created by 海参 on 2022/9/15.
//

#import "CAISegmentCell.h"

@interface CAISegmentCell ()

@property (nonatomic, strong) UILabel *titleLabel;


@end

@implementation CAISegmentCell


- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUI];
        [self addLayout];
    }
    return self;
}


- (void)setUI{
    
    self.selectedColor = [UIColor redColor];
    self.normalColor = [UIColor blackColor];
    [self addSubview:self.titleLabel];
    self.backgroundColor = [UIColor clearColor];
}

- (void)addLayout{
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.titleLabel.frame = self.bounds;
}



- (void)setTitle:(NSString *)title {
    _title = title;
    self.titleLabel.text = title;
}

- (void)setAttributedTitle:(NSAttributedString *)attributedTitle
{
    _attributedTitle = attributedTitle;
    self.titleLabel.attributedText = attributedTitle;
}

- (void)setNormalColor:(UIColor *)normalColor
{
    _normalColor = normalColor;
    if(!self.isSelected){
        self.titleLabel.textColor = normalColor;
    }
}

- (void)setSelectedColor:(UIColor *)selectedColor
{
    _selectedColor = selectedColor;
    if(self.isSelected){
        self.titleLabel.textColor = selectedColor;
    }
}


- (void)setIsSelected:(BOOL)isSelected {
    _isSelected = isSelected;    
    if (isSelected) {
        if (self.selectedFont) {
            self.titleLabel.font = self.selectedFont;
        }
        if (self.selectedColor) {
            self.titleLabel.textColor = self.selectedColor;
        }
    }else{
        if (self.normalFont) {
            self.titleLabel.font = self.normalFont;
        }
        if (self.normalColor) {
            self.titleLabel.textColor = self.normalColor;
        }
    }
}


- (UILabel *)titleLabel {
    if (_titleLabel == nil) {
        UILabel *view = [[UILabel alloc]init];
        view.textAlignment = NSTextAlignmentCenter;
        view.font = [UIFont systemFontOfSize:14];
        _titleLabel = view;
    }
    return _titleLabel;
}

@end
